#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2,re,os,xbmc
path=xbmc.translatePath(os.path.join(os.path.normpath(os.path.join(os.getcwd(),os.pardir,os.pardir)),'hoster'+os.sep+'oracle2'+os.sep+'_divxhoster.py'))

#author:
#FreaX
#
#for details look at default.py
#version: 0.1
#date: 20100505

def check(url):
	if url.rfind("mystream") or url.rfind("tubeload"):
		return 1
	else:
		return 0

def get_regexp():
	return "(http://[w]*\.?mystream.to/file-[^/<>]*.avi|http://[w]*\.?tubeload.to/file-[^/<>]*.avi)"
def get_name():
	return "mystream"
def join(id):
	return id
def get_link1(url):
	#takes an videopage-url of mystream,
	#
	#returnes the service/mirror name, the url that will be passed over to get_link2, the url of the verification code

	BASE_PATH = os.getcwd().replace( ";", "" )
	BASE_DATA_PATH = os.path.join( xbmc.translatePath("special://profile/plugin_data/hoster"), "oracle2" )

		
	req = urllib2.Request(url)
	req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2')
	#req.add_header("Referer", url)
	response = urllib2.urlopen(req)
	page=response.read()
	response.close()
	
	#link = re.compile('"flashvars" value="(.*)"',re.I).findall(page)
	
	link = re.compile("url = '(http://[\S]*avi)'").findall(page)
	if link!=None and len(link)>0:
		return ("got",link[0],'','','','','mystream')
	else:
		return ("fail",'','','','','','mystream')

	
def get_link2(param,code):
		return ("got",param,'','','','','mystream')